const HtmlWebpackPlugin = require('html-webpack-plugin'); // 通过 npm 安装
// const CopyWebpackPlugin = require('copy-webpack-plugin')
const webpack = require('webpack'); // 访问内置的插件
const path = require('path');
function resolve(dir) {
    return path.join(__dirname, '..', dir)
}

module.exports = {
    // 公共入口模块
    // context: path.resolve(__dirname, '../src'),
    // development production
    mode: 'development',
    entry: {
        // // 可创建模块加载选项
        // libs: {
        //     import: ['./src/b.js'],
        //     library: {
        //         // 以库的方式输出对应公共方法模块
        //         name: 'libs',
        //         // 引用插件方式输出模块
        //         type: 'umd',
        //         umdNamedDefine: true,
        //         // 输出模式
        //         export: 'default',
        //         auxiliaryComment: 'Test Comment',
        //     },
        // },
        // 主进程
        main: {
            import: './src/main.js',
            // dependOn: 'libs'
        },
    },
    module: {
        rules: [
            // {
            //     test: /\.js$/,
            //     loader: 'babel-loader',
            //     include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
            // },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
            {
                test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
                loader: 'url-loader',
            },
            // {
            //     test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
            //     loader: 'url-loader',

            // },
            // {
            //     test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
            //     loader: 'url-loader',
            // }, {
            //     test: /\.(html)$/,
            //     use: {
            //         loader: 'html-loader',
            //         options: {
            //             // attrs: false
            //         }
            //     }
            // }
        ]
    },
    output: {
        clean: true,
        charset: true,
        // 输出前缀
        publicPath: './',
        // 输出路径
        path: path.resolve(__dirname, '../dist2'),
        filename: '[name].[chunkhash].js',
    },
    plugins: [
        new webpack.ProgressPlugin(),
        new HtmlWebpackPlugin({
            template: './public/index.html',
            filename: 'index.html',
            title: 'Development',
        }),
    ],
    // devtool: 'cheap-module-eval-source-map',
    devServer: {
        clientLogLevel: 'warning',
        historyApiFallback: {
            rewrites: [
                { from: /.*/, to: path.posix.join('./public/', 'index.html') },
            ],
        },
        hot: true,
        contentBase: false, // since we use CopyWebpackPlugin.
        compress: true,
        // host: IPAdress,
        // port: 8089,
        open: false,
        publicPath: '/',
        proxy: {},
        quiet: true, // necessary for FriendlyErrorsPlugin
    },
};